package com.yic.module.mes.controller.admin.itemproducerouteextend;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.common.pojo.CommonResult;
import static com.yic.framework.common.pojo.CommonResult.success;

import com.yic.framework.excel.core.util.ExcelUtils;

import com.yic.framework.operatelog.core.annotations.OperateLog;
import static com.yic.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.yic.module.mes.controller.admin.itemproducerouteextend.vo.*;
import com.yic.module.mes.dal.dataobject.itemproducerouteextend.ItemProduceRouteExtendDO;
import com.yic.module.mes.convert.itemproducerouteextend.ItemProduceRouteExtendConvert;
import com.yic.module.mes.service.itemproducerouteextend.ItemProduceRouteExtendService;

@Tag(name = "管理后台 - 产品工艺路线配置")
@RestController
@RequestMapping("/mes/item-produce-route-extend")
@Validated
public class ItemProduceRouteExtendController {

    @Resource
    private ItemProduceRouteExtendService itemProduceRouteExtendService;

    @PostMapping("/create")
    @Operation(summary = "创建产品工艺路线配置")
    @PreAuthorize("@ss.hasPermission('mes:item-produce-route-extend:create')")
    public CommonResult<Long> createItemProduceRouteExtend(@Valid @RequestBody ItemProduceRouteExtendCreateReqVO createReqVO) {
        return success(itemProduceRouteExtendService.createItemProduceRouteExtend(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新产品工艺路线配置")
    @PreAuthorize("@ss.hasPermission('mes:item-produce-route-extend:update')")
    public CommonResult<Boolean> updateItemProduceRouteExtend(@Valid @RequestBody ItemProduceRouteExtendUpdateReqVO updateReqVO) {
        itemProduceRouteExtendService.updateItemProduceRouteExtend(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除产品工艺路线配置")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:item-produce-route-extend:delete')")
    public CommonResult<Boolean> deleteItemProduceRouteExtend(@RequestParam("id") Long id) {
        itemProduceRouteExtendService.deleteItemProduceRouteExtend(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得产品工艺路线配置")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('mes:item-produce-route-extend:query')")
    public CommonResult<ItemProduceRouteExtendRespVO> getItemProduceRouteExtend(@RequestParam("id") Long id) {
        ItemProduceRouteExtendDO itemProduceRouteExtend = itemProduceRouteExtendService.getItemProduceRouteExtend(id);
        return success(ItemProduceRouteExtendConvert.INSTANCE.convert(itemProduceRouteExtend));
    }

    @GetMapping("/list")
    @Operation(summary = "获得产品工艺路线配置列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('mes:item-produce-route-extend:query')")
    public CommonResult<List<ItemProduceRouteExtendRespVO>> getItemProduceRouteExtendList(@RequestParam("ids") Collection<Long> ids) {
        List<ItemProduceRouteExtendDO> list = itemProduceRouteExtendService.getItemProduceRouteExtendList(ids);
        return success(ItemProduceRouteExtendConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得产品工艺路线配置分页")
    @PreAuthorize("@ss.hasPermission('mes:item-produce-route-extend:query')")
    public CommonResult<PageResult<ItemProduceRouteExtendRespVO>> getItemProduceRouteExtendPage(@Valid ItemProduceRouteExtendPageReqVO pageVO) {
        PageResult<ItemProduceRouteExtendDO> pageResult = itemProduceRouteExtendService.getItemProduceRouteExtendPage(pageVO);
        return success(ItemProduceRouteExtendConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出产品工艺路线配置 Excel")
    @PreAuthorize("@ss.hasPermission('mes:item-produce-route-extend:export')")
    @OperateLog(type = EXPORT)
    public void exportItemProduceRouteExtendExcel(@Valid ItemProduceRouteExtendExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<ItemProduceRouteExtendDO> list = itemProduceRouteExtendService.getItemProduceRouteExtendList(exportReqVO);
        // 导出 Excel
        List<ItemProduceRouteExtendExcelVO> datas = ItemProduceRouteExtendConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "产品工艺路线配置.xls", "数据", ItemProduceRouteExtendExcelVO.class, datas);
    }

}
